'use strict';

const Controller = require('./base');

class ShopController extends Controller {
  /**
   * find a shop by shop id
   * @param {String} shopId  the shop Id
   */
  async find() {

    const shopId = this.ctx.params.id;

    console.log(shopId, 'shopId');

    const shop = await this.ctx.service.shop.findById(shopId);

    this.success(shop);
  }

  async findAll() {

    const shops = await this.ctx.service.shop.findAll();

    this.success(shops);
  }


  async create() {
    const createRule = {
      shopName: { type: 'string' },
    };
    // 校验参数
    this.ctx.validate(createRule);

    // console.log(this.ctx.request.body, 'this.ctx.request.body');

    const shop = Object.assign(this.ctx.request.body, {});

    await this.ctx.service.shop.create(shop);

    this.success();
  }

  async update() {
    // const createRule = {
    //   shopId: { type: 'string' },
    //   shopName: { type: 'string' },
    // };

    // // 校验参数
    // this.ctx.validate(createRule);

    const shopId = this.ctx.params.id;

    
    console.log(shopId, 'shopId');

    const shop = Object.assign(this.ctx.request.body, {});


    await this.ctx.service.shop.update(shopId, shop);

    this.success();

  }

}

module.exports = ShopController;
